<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .box {
            width: 450px;
            padding: 15px 0;
            margin: 50px auto;
            text-align: center;
            line-height: 60px;
            background-color: rgb(255, 255, 255);
            box-shadow: 0 1px 20px 1px red;

        }

        .box input {
            border: 0;
            border-bottom: 1px solid rgba(0, 0, 0, 0.322);
            height: 40px;
            outline: none;
            font-size: 14px;
        }

        .box label {
            margin-right: 10px;
            font-size: 24px;
            font-weight: bold;
            /* line-height: 40px; */

        }

        button {
            width: 100px;
            height: 40px;
            background-color: black;
            color: white;
        }

        body {
            background-color: aqua;
        }
    </style>
</head>

<body>
    <div class="box">
        <label for="name">账户</label>
        <input type="text" placeholder="请输入账户" id="name"><br>
        <label for="pass">密码</label>
        <input type="password" placeholder="请输入密码" id="pass"><br>
        <button>登录</button>

    </div>

    <script>
        let user = document.querySelector("#name")
        let pass = document.querySelector("#pass")
        let btn = document.querySelector('button')

        btn.onclick = function () {
            if (user.value == "" || pass.value == "") {
                alert("请输入用户名或者密码")
                return
            }         
                let xhr = new XMLHttpRequest()
                xhr.open('post', 'http://wish.byesame.com/login')
                // xhr.setRequestHeader('Content-type', '')
                xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')

                xhr.send(`userName=${user.value}&passWord=${pass.value}`)
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4) {
                        let data = JSON.parse(xhr.responseText)
                        console.log(data);
                        // let tocode
                        if (data.code == 200) {
                            localStorage.setItem('token',data.data.token)
                            window.open("./89完整留言列表.html")
                        } else {
                            alert(data.msg)
                        }

                    }
                
            }
        }


    </script>
</body>

</html>